473,421 Members | 1,500 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

Sorting Number Type

48
Hello,

I am currently using Listview control.
The sorting feature of the control is useful.
Expand|Select|Wrap|Line Numbers
  1. <ListviewCtrlName>.Sorted = True
  2. <ListviewCtrlName>.SortKey = <FieldToSort>
  3. <ListviewCtrlName>.SortOrder = <SortOrder>
It sorts well with Text type but is weird when sorting Number Type.
Ex.
(before sorting)
[1st] 3
[2nd] 2
[3rd] 11
[4th] 4
[5th] 1

(after sorting)
[1st] 1
[2nd] 11
[3rd] 2
[4th] 3
[5th] 4

The correct one should be:
[1st] 1
[2nd] 2
[3rd] 3
[4th] 4
[5th] 11

How to sort number type correctly?
Apr 28 '09 #1
13 4325
ADezii
8,834 Expert 8TB
@keirnus
If you set the SortKey Property = 0 it will Sort using the ListItem Object's Text property. Try setting it to a Value between 1 and Number of ColumnHeaders - 1 to Sort using the SubItem whose Collection Index you specify, then see what happens.
Apr 28 '09 #2
keirnus
48
@ADezii
(I edited this reply coz I was wrong...sorry)

Thanks for the reply ADezii.

But I noticed something. The SortKey is the column index in listview.
It starts with zero(0) so in my example, since there's only 1 column so
it starts with index 0. If I got 3 columns and want to sort the 2nd, I will
be using index 1. (please correct me if I'm wrong)

I tried sorting the column with number type and yet the sorting is wrong.
The sort is treating it like an alpha when it should be numeric.
Apr 28 '09 #3
ADezii
8,834 Expert 8TB
@keirnus
As soon as I get a chance, I'll create a DB with a ListView incorporated in a Form and see if I can 'Sort' the problem (LOL)!
Apr 28 '09 #4
NeoPa
32,556 Expert Mod 16PB
It looks like you're simply sorting on the string value, instead of the numeric value.
Apr 28 '09 #5
NeoPa
32,556 Expert Mod 16PB
@keirnus
Which values are you actually using?
Apr 28 '09 #6
ADezii
8,834 Expert 8TB
@keirnus
Keirnus, I do see your dilemma in that the ListView Control seems to always want to do an Alpha Sort on Column Headers regardless of the Data Type. I'll look into it further at a later Date, but I do have a solution at this time.
  1. In the ColumnClick() Event of the ListView Control, if the Index of the ColumnHeader is anything but the 1st Column, set the SortKey = ColumnHeader.Index -1 then set the Sorted Property of the ListView = True.
  2. If the Index of the ColumnHeader = Column 1, then:
    1. Clear the ListView Control
    2. Set the Sorted Property = False
    3. Create a RecordSet setting the Primary Sort Order of your Numeric Field to Ascending
    4. Re-populate the ListView based on this Recordset
    5. This entire process will be transparent to the User, and, unless you are dealing with very large Recordsets, will populate quite rapidly.
  3. I created a Demo Database for you, simply download the Attachment, then Click on the Column Headers to set the Sorts for the 3 Columns
Apr 28 '09 #7
NeoPa
32,556 Expert Mod 16PB
@keirnus
I'm confused.

I started by assuming you were referring to a ListBox control, but I didn't find any of these properties there so I stopped and looked again.

I found the ListView control, but even there, I found those properties missing.

I'm using Access 2003. Is it possible you're using a different version?
Apr 29 '09 #8
ADezii
8,834 Expert 8TB
@NeoPa
Hello NeoPa, these Properties definately exist for the ListView Control but not via the Normal Interface, you can access them either by:
  1. Right Click the ListView Control ==> ListViewCtrl Object ==> Properties ==> Sorting Tab
  2. Object Browser ==> Class = MSComctlLib ==> Search for ListView ==> Properties, Methods, and Events will appear in the Right Hand Pane
Apr 29 '09 #9
missinglinq
3,532 Expert 2GB
I can't lay my hands on a reference right now, but I'm about 99.9% sure that ListView controls only sort on strings and treat any other datatype as if they were strings when sorting, which is what it's doing here.

Linq ;0)>
Apr 29 '09 #10
ADezii
8,834 Expert 8TB
@missinglinq
I think you hit the nail on the Head, any attempt to Sort on Native Numeric Types, or Data Types coerced to Numeric, seem to fail. It appears as though the ListView must be repopulated as indicated in my prior Post.
Apr 29 '09 #11
NeoPa
32,556 Expert Mod 16PB
@ADezii
Bizarre. It's almost as if I'm looking at a different, unrelated, ListView control.

Method 1 would be default for me. Didn't find anything (not even a sorting tab).
I also tried IntelliSense, but that yielded nothing either.

I'd like to see if I could find a way of coercing the item to a numeric value, but it's hard if I can't even find it.

Never mind.
Apr 29 '09 #12
ADezii
8,834 Expert 8TB
@NeoPa
  1. Are we talking about the same animal, namely:
    Expand|Select|Wrap|Line Numbers
    1. Form Design View ==> Insert ==> ActiveX Control ==> Microsoft ListView Control, version X.X
  2. Did you download the Attachment in Post #7 of this Thread, and is it functional?
Apr 29 '09 #13
NeoPa
32,556 Expert Mod 16PB
  1. I used the Toolbox button and More tools. If this is the same I don't know.
  2. No. I rarely download attachments. I don't often have the time to get into questions that deeply, and I never download anything at my work PC.
PS. It's not important if I don't know too much about this control. I was only interested to see if I could help with the question. As you guys seem to be covering it anyway, it's hardly a problem if I'm on a rail track that is sort of parallel, but verges off on its way to a different city.
Apr 29 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
4
by: Richard | last post by:
When i try sorting in the database, it sorts the numbers: 0 1 102 2 304 305 4 etc....
25
by: Dan Stromberg | last post by:
Hi folks. Python appears to have a good sort method, but when sorting array elements that are very large, and hence have very expensive compares, is there some sort of already-available sort...
9
by: Dylan Parry | last post by:
Hi folks, I have a database that contains records with IDs like "H1, H2, H3, ..., Hn" and these refer to local government policy numbers. For example, H1 might be "Housing Policy 1" and so on....
1
by: DJP | last post by:
Hello all, I am having problems sorting my xml on two fields. For each result I want to sort resultItem elements based on child elements typId and macroSequence. so I want result element like...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.